var componentSelector_cur = false;
$.ajaxSetup ({async: false});

function componentSelector_changeClass (idFieldName, classFieldName) {
	idField = '#' + idFieldName;
	classField = '#' + classFieldName;
	$(idField).load ('/admin/index.php/componentSelector_changeClass/process/className/' + $(classField).val());
}

function componentSelector_pick (idFieldName, classFieldName) {
	componentSelector_cur = new Array (idFieldName, classFieldName);
	$('#' + idFieldName + '_pickbutton').hide();
	$('#' + idFieldName + '_unpickbutton').show();
}

function componentSelector_unpick (idFieldName, classFieldName) {
	componentSelector_cur = false;
	$('#' + idFieldName + '_unpickbutton').hide();
	$('#' + idFieldName + '_pickbutton').show();
}

function componentSelector_click (id, className) {
	if (componentSelector_cur != false) {
		idField = '#' + componentSelector_cur[0];
		classField = '#' + componentSelector_cur[1];
		
		$(classField).val (className).trigger ('change');
		$(idField).val (id);
		
		componentSelector_unpick (componentSelector_cur[0], componentSelector_cur[1]);
		return false;
	}
	else {
		return true;
	}	
}

function styleSelector_changeFolder (fieldName) {
	fileField  = '#' + fieldName + '_file';
	folderField = '#' + fieldName + '_folder';
	hiddenField = '#' + fieldName + '_hidden';
	$(fileField).load ("/admin/index.php/styleSelector_changeFolder/process/folder/" + $(folderField).val());
	$(hiddenField).val ($(folderField).val() + '/' + $(fileField).val());
}

function styleSelector_changeFile (fieldName) {
	fileField  = '#' + fieldName + '_file';
	folderField = '#' + fieldName + '_folder';
	hiddenField = '#' + fieldName + '_hidden';
	$(hiddenField).val ($(folderField).val() + '/' + $(fileField).val());
}

function componentPicker_updateList () {
	url = "/admin/index.php/componentPicker_updateList/process";
	url = url + "/className/" + $('#componentPicker_class').val ();
	url = url + "/title_id/" + $('#componentPicker_title_id').val ();
	$('#componentPicker_list').load (url);
}

function componentPicker_click () {
	if (componentSelector_cur != false) {
		idField = '#' + componentSelector_cur[0];
		classField = '#' + componentSelector_cur[1];
		
		$(classField).val ($('#componentPicker_class').val ()).trigger ('change');
		$(idField).val ($('#componentPicker_list').val());
		
		componentSelector_unpick (componentSelector_cur[0], componentSelector_cur[1]);
	}
	else {
		window.open ("/admin/index.php/process/comId/" + $('#componentPicker_list').val() + "/comClass/" + $('#componentPicker_class').val ());
	}	
}